package com.bawei.rk_01.Home

import androidx.lifecycle.viewModelScope
import com.bawei.base.utils.SingLiveData
import com.bawei.base.utils.bean.GoodEnttiy
import com.bawei.base.utils.bean.Res
import com.bawei.base.utils.mvvm.BaseViewModel
import kotlinx.coroutines.launch
import retrofit2.http.Query

class SearchViewModel : BaseViewModel() {

    val searchsuccess = SingLiveData<Res<GoodEnttiy>>()
    val searchfail = SingLiveData<String>()

    fun search(cid:Int,
               keyword:String,
               limit:Int,
               news:Boolean,
               page:Int,
               priceOrder:String,
               salesOrder:String){
        viewModelScope.launch {
            try {
                searchsuccess.postValue(apiService.searchGoods(cid,keyword,limit,news,page,priceOrder,salesOrder))
            }catch (e:Exception){
                searchfail.postValue(e.message.toString())
            }
        }
    }

}